'''
Created on 16.01.2012

@author: myaut
'''

import sys
import faulthandler

import time

from bench import bench_count_digits

sys.path.append('../../lib')

from salsa.util.io import IOSlave, IOSlaveDead

try:
    try:
        sl = IOSlave(4010)
        sl.start()
        
        sl.put('myaut')    
        sl.get_blocked()
        
        sl.put('I am fine, thank you')
        
        # Benchmark master
        io_bench_start = time.clock()
                
        digits = sl.get()
        
        for data in digits:
            pass
        
        io_bench_end = time.clock()
        
        local_bench_start = time.clock()
        
        for data2 in range(bench_count_digits):
            pass
        
        local_bench_end = time.clock()
        
        print 'IO time: %f' % (io_bench_end - io_bench_start)
        print 'Local time: %f' % (local_bench_start - local_bench_start)
            
    except IOSlaveDead, e:
        raise
    finally:
        sl.stop()
    
except KeyboardInterrupt:
    faulthandler.dump_traceback()
